//
//  YATaskUserSession.m
//  YoucApi
//
//  Created by Liam on 11/25/12.
//
//

#import "YATaskUserSession.h"

@implementation YATaskUserSession

- (NSError *)_checkEnvBeforeProcess
{
	NSError *error = [super _checkEnvBeforeProcess];
	if (!error || [error code] == YoucApiErrorSuccess)
	{
		NSString *sessionKey = [self.params objectForKey:KEY_SESSION];
		
		if (!sessionKey || (sessionKey != nil && [sessionKey isEqualToString:@""]))
		{
			error = [YoucApiError errorWithCode:YoucApiErrorInvalidSession userInfo:nil];
		}
	}
	
	return error;
}

- (NSInteger)apiErrorCodeFromErrorCode:(NSInteger)code
{
    switch (code) {
        case 1:
            code = YoucApiErrorInvalidUserNameOrPassword;
            break;
		case 9:
			code = YoucApiErrorSessionTimeout;
			break;
		case 10:
			code = YoucApiErrorSuccess;
			break;
        default:
			code = [super apiErrorCodeFromErrorCode:code];
            break;
    }
    
    return code;
}

@end
